package com.example.superoa.model.service;

import java.util.Date;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.alibaba.fastjson.JSONArray;
import com.example.superoa.model.dao.TitemDao;
import com.example.superoa.model.mappers.TitemsMapper;
import com.example.superoa.model.pojos.Titem;

@Service
@Transactional(rollbackFor=Exception.class)
public class TitemsService {
		@Autowired
		private TitemsMapper itemmapper;
		@Autowired
		private TitemDao itemdao;
		//查询全部
		public JSONArray findAllsitem() {
			return itemmapper.findAllsitem();
		}
		//根据名字查询
		public JSONArray findByitemname(String titemremark) {
			return itemmapper.findByitemname("%"+titemremark+"%");
		}
		//根据id查询
		public JSONArray findByIditem(int titemid) {
			return itemmapper.findByIditem(titemid);
		}
		//新增
		public void insertitems(Titem items) {
			itemdao.save(items);
		}	
		//初始化
		public JSONArray selectbyid(int titemid) {
			return itemmapper.findByIditem(titemid);
		}
		//修改题库
		public void xiugaiitem(int titemid,String titemremark,String titemanswer,String titemtypes, Date titemdate,String titemall) {
			Titem item = itemdao.findById(titemid).get();
			    item.setTitemanswer(titemanswer);
			    item.setTitemall(titemall);
				item.setTitemdate(titemdate);
				item.setTitemremark(titemremark);
				item.setTitemtypes(titemtypes);
				itemdao.save(item);
				}
}